package com.zhangtong.excel.generator;

import com.zhangtong.excel.Constant;
import com.zhangtong.excel.ExcelContext;
import com.zhangtong.excel.entity.StatisticsData;
import com.zhangtong.excel.entity.Title;
import com.zhangtong.excel.tool.ExcelTool;
import org.apache.poi.ss.usermodel.Row;

import java.math.BigDecimal;

public interface IGenerator {
    void generateRows(StatisticsData statisticsData, Title title, ExcelContext context);

    static void generateCells(String name, String project, BigDecimal worktime, Title title, Row row, ExcelContext context) {
        ExcelTool.createCell(row, 0, context.getCellStyle()).setCellValue(context.getCurrentDataRowIdx()+1);

        for (int i = 1; i <= title.size(); i++) {
            ExcelTool.createCell(row, i, context.getCellStyle());
        }

        int idx = 1;
        for (String titleId : title.keySet()) {
            if (Constant.PROJECT.equals(titleId)) {
                row.getCell(idx).setCellValue(project);
            } else if (Constant.NAME.equals(titleId)) {
                row.getCell(idx).setCellValue(name);
            } else if (Constant.WORKTIME.equals(titleId)) {
                row.getCell(idx).setCellValue(worktime.doubleValue());
            }

            idx++;
        }

      context.addCurrentDataRowIdx();
    }
}
